#pragma once
#include "IObject.h"
#include "NoBaseClass.h"
#include "INotifyOnDeleteCallback.h"

template<typename TI,typename TAddRefPolicy>
class CXcpObjectBaseInternal :
	public TI
{
public: 
	CXcpObjectBaseInternal()
	{
		m_nRefCount = 1;
	}

	virtual ~CXcpObjectBaseInternal()
	{
		NOTIMPL
	}

	XINT32 InternalAddRef()
	{
		return TAddRefPolicy::AddRef(this->m_nRefCount);
	}

	XINT32 InternalRelease()
	{
		int cRefCount;

		cRefCount = TAddRefPolicy::Release(this->m_nRefCount);
		if ( !cRefCount )
		{
			if ( this )
				static_cast<TI *>(this)->Release();
		}
		return cRefCount;
	}

private: 
	XINT32 m_nRefCount;
};


template<typename TAddRefPolicy>
class CXcpObjectBaseInternal<NoBaseClass,TAddRefPolicy> :
	public NoBaseClass
{
public: 
	CXcpObjectBaseInternal()
	{
		m_nRefCount = 1;
	}

	virtual ~CXcpObjectBaseInternal()
	{
		NOTIMPL
	}

	XINT32 InternalAddRef()
	{
		return TAddRefPolicy::AddRef(this->m_nRefCount);
	}

	XINT32 InternalRelease()
	{
		int cRefCount;

		cRefCount = TAddRefPolicy::Release(this->m_nRefCount);
		if ( !cRefCount )
		{
			//if ( this )
			//	static_cast<TI *>(this)->Release();
		}
		return cRefCount;
	}

private: 
	XINT32 m_nRefCount;
};


template<typename TAddRefPolicy>
class CXcpObjectBaseInternal<INotifyOnDeleteCallback,TAddRefPolicy> :
	public INotifyOnDeleteCallback
{
public: 
	CXcpObjectBaseInternal()
	{
		m_nRefCount = 1;
	}

	virtual ~CXcpObjectBaseInternal()
	{
		NOTIMPL
	}

	XINT32 InternalAddRef()
	{
		return TAddRefPolicy::AddRef(this->m_nRefCount);
	}

	XINT32 InternalRelease()
	{
		int cRefCount;

		cRefCount = TAddRefPolicy::Release(this->m_nRefCount);
		if ( !cRefCount )
		{
			//if ( this )
			//	static_cast<TI *>(this)->Release();
		}
		return cRefCount;
	}

private: 
	XINT32 m_nRefCount;
};



